package com.swjd.service.Impl;

import com.swjd.dao.GoodsDao;
import com.swjd.pojo.Goods;
import com.swjd.service.GoodsService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsDao goodsDao;
    @Override
    public Goods findByGoodsDistrict(int goodsDistrict) {
        Goods byGoodsDistrict = goodsDao.findByGoodsDistrict(goodsDistrict);
        return byGoodsDistrict;
    }

    @Override
    public List<Goods> findAll() {
        Iterable<Goods> all = goodsDao.findAll();
        return (List<Goods>) all;
    }

    @Override
    public Goods addGoods(Integer id, String goodsName, Integer goodsDistrict, float goodsPrice, Integer goodsCount, Integer billStatus,
                        Date creationTime) {
        Goods goods = new Goods();
        if (id!=null){
            goods.setId(id);
        }
        if (StringUtils.isNotBlank(goodsName)){
            goods.setGoodsName(goodsName);
        }
        if (goodsDistrict!=null){
            goods.setGoodsDistrict(goodsDistrict);
        }
        goods.setGoodsPrice(goodsPrice);
        if (goodsCount!=null){
            goods.setGoodsCount(goodsCount);
        }
        if (billStatus!=null){
            goods.setBillStatus(billStatus);
        }

            goods.setCreationTime(creationTime);

        Goods save = goodsDao.save(goods);
        return save;
    }


}
